<!DOCTYPE html><html class="theme-next pisces use-motion" lang="zh-CN"><head><meta name="generator" content="Hexo 3.9.0"><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=2"><meta name="theme-color" content="#222"><link rel="apple-touch-icon" sizes="180x180" href="/images/icons/favicon-48.png?v=6.7.0"><link rel="icon" type="image/png" sizes="32x32" href="/images/icons/favicon-32.png?v=6.7.0"><link rel="icon" type="image/png" sizes="16x16" href="/images/icons/favicon-16.png?v=6.7.0"><link rel="mask-icon" href="/images/icons/logo.svg?v=6.7.0" color="#222"><link rel="alternate" href="/atom.xml" title="菠菜眾長" type="application/atom+xml"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><link href="/lib/fancybox/source/jquery.fancybox.css" rel="stylesheet" type="text/css"><link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css"><link href="/css/main.css?v=6.7.0" rel="stylesheet" type="text/css"><script type="text/javascript" id="hexo.configurations">var NexT=window.NexT||{},CONFIG={root:"/",scheme:"Pisces",version:"6.7.0",sidebar:{position:"left",display:"always",offset:12,b2t:!1,scrollpercent:!0,onmobile:!0},fancybox:!0,fastclick:!0,lazyload:!0,tabs:!0,motion:{enable:!0,async:!0,transition:{post_block:"fadeIn",post_header:"slideDownIn",post_body:"slideDownIn",coll_header:"slideLeftIn",sidebar:"slideUpIn"}},algolia:{applicationID:"",apiKey:"",indexName:"",hits:{per_page:10},labels:{input_placeholder:"Search for Posts",hits_empty:"We didn't find any results for the search: ${query}",hits_stats:"${hits} results found in ${time} ms"}}}</script><meta name="baidu-site-verification" content="B2fOjPkYa7"><meta name="google-site-verification" content="OhdtVOx5uwpZ_mMm0AZJXzw-dY1PPpAAkdavmmQhIL4"><meta name="360-site-verification" content="5b1c9d7574859ca6e460dd687667d5dc"><meta name="shenma-site-verification" content="933461d02e7b7c40e5293ee90085127c_1569650330"><meta name="description" content="后面几天讲的有点杂，简单记录一下知识点。"><meta name="keywords" content="Python"><meta property="og:type" content="article"><meta property="og:title" content="python实训总结Ⅱ"><meta property="og:url" content="https://lruihao.cn/posts/pysx2.html"><meta property="og:site_name" content="菠菜眾長"><meta property="og:description" content="后面几天讲的有点杂，简单记录一下知识点。"><meta property="og:locale" content="zh-CN"><meta property="og:image" content="https://lruihao.cn/images/loading_img.gif"><meta property="og:image" content="https://lruihao.cn/images/loading_img.gif"><meta property="og:image" content="https://lruihao.cn/images/loading_img.gif"><meta property="og:updated_time" content="2019-10-19T02:46:42.761Z"><meta name="twitter:card" content="summary"><meta name="twitter:title" content="python实训总结Ⅱ"><meta name="twitter:description" content="后面几天讲的有点杂，简单记录一下知识点。"><meta name="twitter:image" content="https://lruihao.cn/images/loading_img.gif"><link rel="alternate" href="/atom.xml" title="菠菜眾長" type="application/atom+xml"><link rel="canonical" href="https://lruihao.cn/posts/pysx2.html"><script type="text/javascript" id="page.configurations">CONFIG.page={sidebar:""}</script><title>python实训总结Ⅱ | 菠菜眾長</title><script type="text/javascript">var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?d25f1e053205bf07562f33365fef04d7";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}()</script><noscript><style type="text/css">.sidebar-inner,.use-motion .brand,.use-motion .collection-title,.use-motion .comments,.use-motion .menu-item,.use-motion .motion-element,.use-motion .pagination,.use-motion .post-block,.use-motion .post-body,.use-motion .post-header{opacity:initial}.use-motion .logo,.use-motion .site-subtitle,.use-motion .site-title{opacity:initial;top:initial}.logo-line-after i{right:initial}</style></noscript></head><body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN"><div class="container sidebar-position-left page-post-detail"><div class="headband"></div><header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="header-inner"><div class="site-brand-wrapper"><div class="site-meta"><div class="custom-logo-site-title"><a href="/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title">菠菜众长</span> <span class="logo-line-after"><i></i></span></a></div><h1 class="site-subtitle" itemprop="description">李瑞豪的博客</h1></div><div class="site-nav-toggle"><button aria-label="切换导航栏"><span class="btn-bar"></span> <span class="btn-bar"></span> <span class="btn-bar"></span></button></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i><br>首页</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i><br>归档<span class="badge">176</span></a></li><li class="menu-item menu-item-docs"><a href="/docs/" rel="section"><i class="menu-item-icon fa fa-fw fa-book"></i><br>综合</a></li><li class="menu-item menu-item-album"><a href="https://img.lruihao.cn" rel="external nofollow noopener noreferrer" target="_blank"><i class="menu-item-icon fa fa-fw fa-image"></i><br>相册</a></li><li class="menu-item menu-item-guestbook"><a href="/guestbook/" rel="section"><i class="menu-item-icon fa fa-fw fa-comments"></i><br>留言</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-address-card"></i><br>关于</a></li><li class="menu-item menu-item-search"><a href="javascript:;" class="popup-trigger"><i class="menu-item-icon fa fa-search fa-fw"></i><br>搜索</a></li></ul><div class="site-search"><div class="popup search-popup local-search-popup"><div class="local-search-header clearfix"><span class="search-icon"><i class="fa fa-search"></i> </span><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span><div class="local-search-input-wrapper"><input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input"></div></div><div id="local-search-result"><div style="text-align:center;padding:3px 0 0"><div style="margin-top:20px;font-size:18px;font-weight:600;border-bottom:1px solid #ccc"><i class="fa fa-history" aria-hidden="true"></i> 近期文章</div><ul style="margin:0;padding:0;list-style:none"><li><a href="/posts/csdnvisiter.html" title="使用Python刷csdn访问量" target="_blank">使用Python刷csdn访问量</a></li><li><a href="/posts/cron.html" title="CRON表达式的基本语法" target="_blank">CRON表达式的基本语法</a></li><li><a href="/posts/daka.html" title="新冠疫情未返校未返工第N天之“自动打卡”" target="_blank">新冠疫情未返校未返工第N天之“自动打卡”</a></li><li><a href="/posts/year-2019.html" title="2019年度总结" target="_blank">2019年度总结</a></li><li><a href="/posts/sql.html" title="SQL总结" target="_blank">SQL总结</a></li><li><a href="/posts/cos-album.html" title="利用腾讯云为静态页面添加“动态”相册" target="_blank">利用腾讯云为静态页面添加“动态”相册</a></li><li><a href="/posts/restful.html" title="RESTful" target="_blank">RESTful</a></li><li><a href="/posts/phpPushUrl.html" title="php同时主动推送链接到百度，神马等站长平台" target="_blank">php同时主动推送链接到百度，神马等站长平台</a></li><li><a href="/posts/phpfile.html" title="php按行读取文件信息" target="_blank">php按行读取文件信息</a></li><li><a href="/posts/site-time.html" title="设置网站运行时间" target="_blank">设置网站运行时间</a></li><li><a href="/posts/async-defer.html" title="script的三种加载方式（async、defer）" target="_blank">script的三种加载方式（async、defer）</a></li><li><a href="/posts/Sublime-Text3.html" title="Sublime Text3快捷键大全" target="_blank">Sublime Text3快捷键大全</a></li><li><a href="/posts/netBeans.html" title="netBeans IDE开发设置" target="_blank">netBeans IDE开发设置</a></li><li><a href="/posts/dev-rules.html" title="web开发规则，代码规范" target="_blank">web开发规则，代码规范</a></li><li><a href="/posts/phpform.html" title="简单评论模块--php表单练习" target="_blank">简单评论模块--php表单练习</a></li></ul></div></div></div></div></nav></div></header><a href="https://github.com/Lruihao/lruihao.github.io" class="github-corner" target="_blank" title="万水千山总是情,给个star行不行！" aria-label="万水千山总是情,给个star行不行！" rel="external nofollow noopener noreferrer"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#222;color:#fff;position:absolute;top:0;border:0;right:0" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin:130px 106px" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><main id="main" class="main"><div class="main-inner"><div class="content-wrap"><div id="content" class="content"><div id="posts" class="posts-expand"><div class="reading-progress-bar"></div><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-block"><link itemprop="mainEntityOfPage" href="https://lruihao.cn/posts/pysx2.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content="李瑞豪"><meta itemprop="description" content="从ACM到Web，分享程序、技巧、干货，记录心情、学习、成长！"><meta itemprop="image" content="/images/avatar.png"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="菠菜眾長"></span><header class="post-header"><h2 class="post-title" itemprop="name headline"><span class="post-delicate-flag" title="精品"><i class="fa fa-newspaper-o"></i> </span>python实训总结Ⅱ<a href="https://github.com/Lruihao/lruihao.github.io/tree/hexo/source/_posts/pysx2.md" class="post-edit-link" title="编辑" rel="external nofollow noopener noreferrer" target="_blank"><i class="fa fa-pencil"></i></a></h2><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建时间：2019-06-21 18:46:41" itemprop="dateCreated datePublished" datetime="2019-06-21T18:46:41+08:00">2019-06-21</time> </span><span class="post-category"><span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-folder-o"></i> </span><span class="post-meta-item-text">分类于</span> <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/Backend/" itemprop="url" rel="index"><span itemprop="name">Backend</span></a></span> ， <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/Backend/Python/" itemprop="url" rel="index"><span itemprop="name">Python</span></a></span> </span><span class="post-comments-count"><span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-comment-o"></i> </span><span class="post-meta-item-text">评论数： </span><a href="/posts/pysx2.html#comments" itemprop="discussionUrl"><span class="post-comments-count valine-comment-count" data-xid="/posts/pysx2.html" itemprop="commentCount"></span> </a></span><span id="/posts/pysx2.html" class="leancloud_visitors" data-flag-title="python实训总结Ⅱ"><span class="post-meta-divider">|</span> <span title="阅读次数"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">阅读次数：</span> <span class="leancloud-visitors-count"></span></span></span><div class="post-symbolscount"><span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-file-word-o"></i> </span><span class="post-meta-item-text">本文字数：</span> <span title="本文字数">4,151</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-clock-o"></i> </span><span class="post-meta-item-text">阅读时长 &asymp;</span> <span title="阅读时长">20 分钟</span></div></div></header><div class="post-body" itemprop="articleBody"><div class="note info no-icon"><p>后面几天讲的有点杂，简单记录一下知识点。</p></div><a id="more"></a><h1 id="6-19"><a href="#6-19" class="headerlink" title="6.19"></a>6.19</h1><blockquote><p>这些知识点在课上都只是简单的提到了一下。<br>比如一些库的使用与安装都不会再课上详细讲解，需要课后再去研究。</p></blockquote><h2 id="切片操作"><a href="#切片操作" class="headerlink" title="切片操作"></a><a href="https://www.jianshu.com/p/15715d6f4dad" rel="external nofollow noopener noreferrer" target="_blank">切片操作</a></h2><p>列表切片操作</p><h2 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h2><h3 id="python原始字符串"><a href="#python原始字符串" class="headerlink" title="python原始字符串"></a>python原始字符串</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">print(<span class="string">r"D:\three\two"</span>)</span><br></pre></td></tr></table></figure><h3 id="长字符串"><a href="#长字符串" class="headerlink" title="长字符串"></a>长字符串</h3><p>用三个单引号或者双引号包裹，前后呼应，成双成对。</p><h3 id="用-换行字符表示字符未结束"><a href="#用-换行字符表示字符未结束" class="headerlink" title="用\换行字符表示字符未结束"></a>用\换行字符表示字符未结束</h3><h2 id="格式化输出format"><a href="#格式化输出format" class="headerlink" title="格式化输出format"></a>格式化输出format</h2><p><code>&quot;=={}==&quot;</code>，<code>{}</code>表示占位符，其前后字符保持原样输出。</p><figure class="highlight py"><figcaption><span>TempConvert.py</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#TempConvert.py</span></span><br><span class="line">TempStr = input(<span class="string">"请输入带有符号的温度值: "</span>)</span><br><span class="line"><span class="keyword">if</span> TempStr[<span class="number">-1</span>] <span class="keyword">in</span> [<span class="string">'F'</span>,<span class="string">'f'</span>]:</span><br><span class="line">    C = (eval(TempStr[<span class="number">0</span>:<span class="number">-1</span>]) - <span class="number">32</span>)/<span class="number">1.8</span></span><br><span class="line">    print(<span class="string">"转换后的温度是&#123;:.2f&#125;C"</span>.format(C))</span><br><span class="line"><span class="keyword">elif</span> TempStr[<span class="number">-1</span>] <span class="keyword">in</span> [<span class="string">'C'</span>,<span class="string">'c'</span>]:</span><br><span class="line">    F = <span class="number">1.8</span>*eval(TempStr[<span class="number">0</span>:<span class="number">-1</span>]) + <span class="number">32</span></span><br><span class="line">    print(<span class="string">"转换后的温度是&#123;:.2f&#125;F"</span>.format(F))</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">    print(<span class="string">"输入格式错误"</span>)</span><br></pre></td></tr></table></figure><h2 id="多变量赋值与交换（斐波那契数列）"><a href="#多变量赋值与交换（斐波那契数列）" class="headerlink" title="多变量赋值与交换（斐波那契数列）"></a>多变量赋值与交换（斐波那契数列）</h2><p>python 3.x版本 <code>end=&quot;&quot;</code> 可使输出不换行<br></p><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">print(x, end=<span class="string">""</span>)</span><br></pre></td></tr></table></figure><p></p><figure class="highlight py"><figcaption><span>斐波那契数列</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#斐波那契数列</span></span><br><span class="line">a, b = <span class="number">1</span>,<span class="number">1</span></span><br><span class="line"><span class="keyword">while</span> a &lt; <span class="number">500</span>: <span class="comment"># 输出不大于500 的序列</span></span><br><span class="line">    print(a,end=<span class="string">","</span>)</span><br><span class="line">    a,b = b,a + b <span class="comment">#交换变量</span></span><br></pre></td></tr></table></figure><h2 id="笑傲江湖统计字符-dict-文件流"><a href="#笑傲江湖统计字符-dict-文件流" class="headerlink" title="笑傲江湖统计字符(dict,文件流)"></a>笑傲江湖统计字符(dict,文件流)</h2><blockquote><p>统计《笑傲江湖》小说中出现的所有中文字符及标点符号的数量，每个字符及数目间用冒号<code>:</code>隔开，例如”笑:1024”，将所有字符及数量的对应采用逗号分隔，以CSV文件格式保存到<code>“笑傲江湖--字符统计.txt”</code>文件中。注意，统计字符不包括空格和回车。</p></blockquote><blockquote><p>csv文件格式： ‘,’逗号连接元素</p></blockquote><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">fi = open(<span class="string">"data/笑傲江湖-网络版.txt"</span>,<span class="string">"r"</span>,encoding=<span class="string">"utf-8"</span>)</span><br><span class="line">fo = open(<span class="string">"data/笑傲江湖-字符统计.txt"</span>,<span class="string">"w"</span>,encoding=<span class="string">"utf-8"</span>)</span><br><span class="line"></span><br><span class="line">txt = fi.read() <span class="comment">#打开文件</span></span><br><span class="line"><span class="comment">#txt</span></span><br><span class="line">d = &#123;&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> c <span class="keyword">in</span> txt:</span><br><span class="line">    d[c] = d.get(c,<span class="number">0</span>)+<span class="number">1</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">del</span> d[<span class="string">' '</span>] <span class="comment">#删除字典中的空格和回车的键值对</span></span><br><span class="line"><span class="keyword">del</span> d[<span class="string">'\n'</span>]</span><br><span class="line"></span><br><span class="line">ls = []</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> key <span class="keyword">in</span> d:</span><br><span class="line">    ls.append(<span class="string">"&#123;&#125;:&#123;&#125;"</span>.format(key,d[key]))</span><br><span class="line"></span><br><span class="line">fo.write(<span class="string">","</span>.join(ls)) </span><br><span class="line">fi.close()</span><br><span class="line">fo.close()</span><br></pre></td></tr></table></figure><img src="/images/loading_img.gif" data-original="/posts/pysx2/tj.png" title="文件读取及字符统计结果"><h2 id="numpy模块"><a href="#numpy模块" class="headerlink" title="numpy模块"></a>numpy模块</h2><p><strong>…</strong></p><h2 id="pandas模块"><a href="#pandas模块" class="headerlink" title="pandas模块"></a>pandas模块</h2><p><strong>…</strong></p><h1 id="6-20"><a href="#6-20" class="headerlink" title="6.20"></a>6.20</h1><h2 id="matplotlib绘图"><a href="#matplotlib绘图" class="headerlink" title="matplotlib绘图"></a>matplotlib绘图</h2><figure class="highlight py"><figcaption><span>指数函数</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line">x = np.arange(<span class="number">-5</span>,<span class="number">5</span>,<span class="number">0.01</span>)</span><br><span class="line">y = <span class="number">2</span>**x+<span class="number">1</span></span><br><span class="line">plt.plot(x,y)</span><br><span class="line">plt.title(<span class="string">"y=2^x+1"</span>,fontsize=<span class="number">24</span>)</span><br><span class="line">plt.xlabel(<span class="string">"X"</span>,fontsize=<span class="number">14</span>)</span><br><span class="line">plt.ylabel(<span class="string">"Y"</span>,fontsize=<span class="number">14</span>)</span><br><span class="line">plt.tick_params(axis=<span class="string">"both"</span>,labelsize=<span class="number">14</span>)</span><br><span class="line">plt.show()</span><br></pre></td></tr></table></figure><img src="/images/loading_img.gif" data-original="/posts/pysx2/zhishu.png" title="Y=2<sup>X</sup>+1"><h2 id="爬虫"><a href="#爬虫" class="headerlink" title="爬虫"></a>爬虫</h2><p>举了一个金融界，炒股，获取数据的爬虫<br>（今天没仔细听课，这数据爬过什么意思，咱不懂，咱也不敢问！）<br></p><figure class="highlight py"><figcaption><span>stock15</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#! /usr/bin/env python </span></span><br><span class="line"><span class="comment">#-*- encoding: utf-8 -*- </span></span><br><span class="line"><span class="comment">#author pythontab.com </span></span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">import</span> pandas <span class="keyword">as</span> pd</span><br><span class="line"><span class="keyword">import</span> pandas_datareader.data <span class="keyword">as</span> web</span><br><span class="line"><span class="keyword">import</span> datetime</span><br><span class="line"><span class="comment">#import tushare as ts</span></span><br><span class="line"></span><br><span class="line">df_stockload = web.DataReader(<span class="string">"000001.SS"</span>, <span class="string">"yahoo"</span>, datetime.datetime(<span class="number">2017</span>,<span class="number">1</span>,<span class="number">1</span>), datetime.date.today())</span><br><span class="line"><span class="comment">#print(type(datetime.datetime.now().strftime('%Y-%m-%d')))</span></span><br><span class="line"><span class="comment">#df_stockload = ts.get_hist_data('sh',start='2017-01-01',end=datetime.datetime.now().strftime('%Y-%m-%d'))</span></span><br><span class="line"><span class="keyword">print</span> (df_stockload.columns)<span class="comment">#查看列名</span></span><br><span class="line"><span class="keyword">print</span> (df_stockload.index)<span class="comment">#查看索引</span></span><br><span class="line"><span class="keyword">print</span> (df_stockload.describe())<span class="comment">#查看各列数据描述性统计</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#绘制移动平均线</span></span><br><span class="line">df_stockload.Close.plot(c=<span class="string">'b'</span>)</span><br><span class="line">df_stockload.Close.rolling(window=<span class="number">30</span>).mean().plot(c=<span class="string">'r'</span>) <span class="comment">#pd.rolling_mean(df_stockload.Close,window=30).plot(c='r')</span></span><br><span class="line">df_stockload.Close.rolling(window=<span class="number">60</span>).mean().plot(c=<span class="string">'g'</span>) <span class="comment">#pd.rolling_mean(df_stockload.Close,window=60).plot(c='g')</span></span><br><span class="line">plt.legend([<span class="string">'Close'</span>,<span class="string">'30ave'</span>,<span class="string">'60ave'</span>],loc=<span class="string">'best'</span>)</span><br><span class="line">plt.show()</span><br></pre></td></tr></table></figure><p></p><figure class="highlight py"><figcaption><span>结果</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">Index([<span class="string">'High'</span>, <span class="string">'Low'</span>, <span class="string">'Open'</span>, <span class="string">'Close'</span>, <span class="string">'Volume'</span>, <span class="string">'Adj Close'</span>], dtype=<span class="string">'object'</span>)</span><br><span class="line">DatetimeIndex([<span class="string">'2017-01-03'</span>, <span class="string">'2017-01-04'</span>, <span class="string">'2017-01-05'</span>, <span class="string">'2017-01-06'</span>,</span><br><span class="line">               <span class="string">'2017-01-09'</span>, <span class="string">'2017-01-10'</span>, <span class="string">'2017-01-11'</span>, <span class="string">'2017-01-12'</span>,</span><br><span class="line">               <span class="string">'2017-01-13'</span>, <span class="string">'2017-01-16'</span>,</span><br><span class="line">               ...</span><br><span class="line">               <span class="string">'2019-06-05'</span>, <span class="string">'2019-06-06'</span>, <span class="string">'2019-06-10'</span>, <span class="string">'2019-06-11'</span>,</span><br><span class="line">               <span class="string">'2019-06-12'</span>, <span class="string">'2019-06-13'</span>, <span class="string">'2019-06-14'</span>, <span class="string">'2019-06-19'</span>,</span><br><span class="line">               <span class="string">'2019-06-20'</span>, <span class="string">'2019-06-21'</span>],</span><br><span class="line">              dtype=<span class="string">'datetime64[ns]'</span>, name=<span class="string">'Date'</span>, length=<span class="number">596</span>, freq=<span class="keyword">None</span>)</span><br><span class="line">              High          Low         Open        Close        Volume  \</span><br><span class="line">count   <span class="number">596.000000</span>   <span class="number">596.000000</span>   <span class="number">596.000000</span>   <span class="number">596.000000</span>  <span class="number">5.960000e+02</span>   </span><br><span class="line">mean   <span class="number">3076.147753</span>  <span class="number">3039.201569</span>  <span class="number">3056.960338</span>  <span class="number">3060.169056</span>  <span class="number">5.098201e+06</span>   </span><br><span class="line">std     <span class="number">269.276147</span>   <span class="number">273.757358</span>   <span class="number">271.612122</span>   <span class="number">272.072346</span>  <span class="number">1.199107e+08</span>   </span><br><span class="line">min    <span class="number">2488.479004</span>  <span class="number">2440.906982</span>  <span class="number">2446.019043</span>  <span class="number">2464.363037</span>  <span class="number">8.820000e+04</span>   </span><br><span class="line"><span class="number">25</span>%    <span class="number">2845.308228</span>  <span class="number">2800.168762</span>  <span class="number">2825.239502</span>  <span class="number">2827.754822</span>  <span class="number">1.375250e+05</span>   </span><br><span class="line"><span class="number">50</span>%    <span class="number">3153.184937</span>  <span class="number">3118.613525</span>  <span class="number">3134.300537</span>  <span class="number">3139.085449</span>  <span class="number">1.666500e+05</span>   </span><br><span class="line"><span class="number">75</span>%    <span class="number">3280.115234</span>  <span class="number">3244.825256</span>  <span class="number">3265.322021</span>  <span class="number">3268.600342</span>  <span class="number">2.091250e+05</span>   </span><br><span class="line">max    <span class="number">3587.031982</span>  <span class="number">3534.195068</span>  <span class="number">3563.639893</span>  <span class="number">3559.465088</span>  <span class="number">2.927580e+09</span>   </span><br><span class="line"></span><br><span class="line">         Adj Close  </span><br><span class="line">count   <span class="number">596.000000</span>  </span><br><span class="line">mean   <span class="number">3060.169056</span>  </span><br><span class="line">std     <span class="number">272.072346</span>  </span><br><span class="line">min    <span class="number">2464.363037</span>  </span><br><span class="line"><span class="number">25</span>%    <span class="number">2827.754822</span>  </span><br><span class="line"><span class="number">50</span>%    <span class="number">3139.085449</span>  </span><br><span class="line"><span class="number">75</span>%    <span class="number">3268.600342</span>  </span><br><span class="line">max    <span class="number">3559.465088</span></span><br></pre></td></tr></table></figure><img src="/images/loading_img.gif" data-original="/posts/pysx2/stock15.png" title="生成的图"><h1 id="6-21"><a href="#6-21" class="headerlink" title="6.21"></a>6.21</h1><h2 id="类"><a href="#类" class="headerlink" title="类"></a>类</h2><p>比第一天稍微仔细一点讲了一下类,有点需要注意：</p><ul><li><code>self</code>相当于<code>this</code>表示当前对象</li><li>python类的所有函数的第一个参数都要写<code>self</code>参数，self也可以是其他的比如<code>lrh</code>等字符替代，但是必须保持一致。</li><li><code>__</code>表示私有的</li><li>class的定义可以不加(),()内可写继承的父类</li></ul><h2 id="GUI设计-wxPython"><a href="#GUI设计-wxPython" class="headerlink" title="GUI设计 wxPython"></a>GUI设计 <a href="https://blog.csdn.net/mist99/article/details/80742548" rel="external nofollow noopener noreferrer" target="_blank">wxPython</a></h2><figure class="highlight plain"><figcaption><span>安装</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip install wxPython</span><br></pre></td></tr></table></figure><figure class="highlight py"><figcaption><span>导入</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> wx</span><br></pre></td></tr></table></figure><figure class="highlight py"><figcaption><span>基本架构</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> wx <span class="comment">#导入wxPython库</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Panel</span><span class="params">(wx.Panel)</span>:</span>  </span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self,parent)</span>:</span>  </span><br><span class="line"></span><br><span class="line">        wx.Panel.__init__(self,parent=parent, id=<span class="number">-1</span>)  </span><br><span class="line"></span><br><span class="line">        <span class="keyword">pass</span>     </span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Frame</span><span class="params">(wx.Frame)</span>:</span>   </span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span>   </span><br><span class="line"></span><br><span class="line">        wx.Frame.__init__(self, parent = <span class="keyword">None</span>, title = <span class="string">u'量化软件'</span>, size=(<span class="number">1000</span>,<span class="number">600</span>), style=wx.DEFAULT_FRAME_STYLE^wx.MAXIMIZE_BOX)   </span><br><span class="line"></span><br><span class="line">        self.DispPanel= Panel(self)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">pass</span>            </span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">App</span><span class="params">(wx.App)</span>:</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">OnInit</span><span class="params">(self)</span>:</span></span><br><span class="line"></span><br><span class="line">        self.frame = Frame()  </span><br><span class="line"></span><br><span class="line">        self.frame.Show()</span><br><span class="line"></span><br><span class="line">        self.SetTopWindow(self.frame)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">True</span>    </span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:   </span><br><span class="line"></span><br><span class="line">    app = App()</span><br><span class="line"></span><br><span class="line">    app.MainLoop()</span><br></pre></td></tr></table></figure><figure class="highlight py"><figcaption><span>helloworld</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> wx</span><br><span class="line"></span><br><span class="line">app = wx.App()</span><br><span class="line">window = wx.Frame(<span class="keyword">None</span>, title=<span class="string">"wxPython 你好！"</span>, size=(<span class="number">400</span>, <span class="number">300</span>))</span><br><span class="line">panel = wx.Panel(window)</span><br><span class="line">label = wx.StaticText(panel, label=<span class="string">"Hello World"</span>, pos=(<span class="number">100</span>, <span class="number">100</span>))</span><br><span class="line">window.Show(<span class="keyword">True</span>)</span><br><span class="line">app.MainLoop()</span><br></pre></td></tr></table></figure><h2 id="talib库的安装"><a href="#talib库的安装" class="headerlink" title="talib库的安装"></a>talib库的安装</h2><p><a href="https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib" rel="external nofollow noopener noreferrer" target="_blank">下载whl文件</a></p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pip install TA_Lib-0.4.17-cp37-cp37m-win_amd64.whl</span><br><span class="line">pip install TA-Lib</span><br></pre></td></tr></table></figure><h2 id="选择排序递归版"><a href="#选择排序递归版" class="headerlink" title="选择排序递归版"></a>选择排序递归版</h2><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">SelectSort</span><span class="params">(L)</span>:</span></span><br><span class="line">    L=L[:]</span><br><span class="line">    <span class="keyword">if</span> len(L)&lt;=<span class="number">1</span>:</span><br><span class="line">        <span class="keyword">return</span> L</span><br><span class="line">    min = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">1</span>,len(L)):</span><br><span class="line">        <span class="keyword">if</span> L[i]&lt;L[min]:</span><br><span class="line">            min = i</span><br><span class="line">    L[min],L[<span class="number">0</span>] = L[<span class="number">0</span>],L[min]</span><br><span class="line">    <span class="keyword">return</span> [L[<span class="number">0</span>]]+SelectSort(L[<span class="number">1</span>:])</span><br><span class="line"></span><br><span class="line">L = [<span class="number">5</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">6</span>,<span class="number">1</span>,<span class="number">9</span>,<span class="number">8</span>,<span class="number">10</span>,<span class="number">0</span>]</span><br><span class="line">print(SelectSort(L))</span><br></pre></td></tr></table></figure><figure class="highlight py"><figcaption><span>结果</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">8</span>, <span class="number">9</span>, <span class="number">10</span>]</span><br></pre></td></tr></table></figure><h2 id="机房上机系统-自我实践"><a href="#机房上机系统-自我实践" class="headerlink" title="机房上机系统(自我实践)"></a>机房上机系统(自我实践)</h2><figure class="highlight py"><figcaption><span>简单机房上机系统源码</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> time</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">student</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self,stu_no=<span class="string">""</span>,stu_name=<span class="string">""</span>,stu_xi=<span class="string">""</span>,stu_time=<span class="string">""</span>)</span>:</span></span><br><span class="line">        self.stu_no = stu_no</span><br><span class="line">        self.stu_name = stu_name</span><br><span class="line">        self.stu_xi = stu_xi</span><br><span class="line">        self.stu_time = stu_time</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">print</span><span class="params">(self)</span>:</span></span><br><span class="line">        print(<span class="string">"学号："</span>+self.stu_no+<span class="string">"\t姓名："</span>+self.stu_name+<span class="string">"\t系别："</span>+self.stu_xi+<span class="string">"\t机时(h)："</span>+self.stu_time)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get_stu_name</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="keyword">return</span> self.stu_name</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get_stu_time</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="keyword">return</span> int(self.stu_time)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">set_stu_time</span><span class="params">(self,add_time)</span>:</span></span><br><span class="line">        self.stu_time = add_time</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">menu</span><span class="params">()</span>:</span></span><br><span class="line">    print(<span class="string">"\t机房上机系统V0.1"</span>)</span><br><span class="line">    print(<span class="string">"********************************"</span>)</span><br><span class="line">    print(<span class="string">"\t—&gt;1.录入学生信息"</span>)</span><br><span class="line">    print(<span class="string">"\t—&gt;2.上机"</span>)</span><br><span class="line">    print(<span class="string">"\t—&gt;3.下机"</span>)</span><br><span class="line">    print(<span class="string">"\t—&gt;4.缴费"</span>)</span><br><span class="line">    print(<span class="string">"\t—&gt;5.退出"</span>)</span><br><span class="line">    print(<span class="string">"********************************"</span>)</span><br><span class="line">    select = eval(input(<span class="string">"请输入序号："</span>))</span><br><span class="line">    <span class="keyword">while</span> select <span class="keyword">not</span> <span class="keyword">in</span> [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>]:</span><br><span class="line">        print(<span class="string">"输入错误，请重新输入！"</span>)</span><br><span class="line">        select = eval(input(<span class="string">"请输入序号："</span>))</span><br><span class="line">    <span class="keyword">return</span> select</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get_time</span><span class="params">()</span>:</span> <span class="comment">#获取当前时间</span></span><br><span class="line">    <span class="keyword">return</span> time.strftime(<span class="string">"%H:%M:%S"</span>, time.localtime()) </span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="comment"># 全局变量</span></span><br><span class="line">    text = [] <span class="comment"># 上机记录列表</span></span><br><span class="line">    start_time = <span class="string">""</span></span><br><span class="line">    end_time = <span class="string">""</span></span><br><span class="line">    sum = <span class="number">0</span> <span class="comment"># 本系统按小时计费，不足一小时按一小时算</span></span><br><span class="line">    people = student()</span><br><span class="line">    online_flag = <span class="keyword">False</span></span><br><span class="line">    down_flag = <span class="keyword">False</span></span><br><span class="line">    input_flag = <span class="keyword">False</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">while</span> <span class="keyword">True</span>:</span><br><span class="line">        select = menu() <span class="comment"># 启用菜单</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> select == <span class="number">1</span>:</span><br><span class="line">            <span class="keyword">if</span> input_flag:</span><br><span class="line">                print(<span class="string">"已录入，无需重复操作，缴费请输入4:"</span>)</span><br><span class="line">                <span class="keyword">continue</span></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                input_flag = <span class="keyword">True</span></span><br><span class="line">                stu_no = input(<span class="string">"请输入学号："</span>)</span><br><span class="line">                stu_name = input(<span class="string">"请输入姓名："</span>)</span><br><span class="line">                stu_xi = input(<span class="string">"请输入系别："</span>)</span><br><span class="line">                stu_time = input(<span class="string">"请输入机时："</span>)</span><br><span class="line">                people = student(stu_no,stu_name,stu_xi,stu_time)</span><br><span class="line">                people.print()</span><br><span class="line">                <span class="keyword">continue</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">elif</span> select == <span class="number">2</span>:</span><br><span class="line">            <span class="keyword">if</span> <span class="keyword">not</span> input_flag:</span><br><span class="line">                print(<span class="string">"未录入学生信息，请录入！"</span>)</span><br><span class="line">                <span class="keyword">continue</span></span><br><span class="line">            <span class="keyword">if</span> <span class="keyword">not</span> online_flag:</span><br><span class="line">                online_flag = <span class="keyword">True</span></span><br><span class="line">                start_time = get_time()</span><br><span class="line">                start_num = int(start_time[<span class="number">0</span>:<span class="number">2</span>])</span><br><span class="line">                <span class="comment">#print(start_num)</span></span><br><span class="line"></span><br><span class="line">                text.append(<span class="string">"上机时间："</span>+start_time)</span><br><span class="line">                print(<span class="string">"已上机！上机时间为："</span>+start_time)</span><br><span class="line">                <span class="keyword">continue</span></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                print(<span class="string">"已上机！上机时间为："</span>+start_time)</span><br><span class="line">                <span class="keyword">continue</span></span><br><span class="line">            </span><br><span class="line">        <span class="keyword">elif</span> select == <span class="number">3</span>:</span><br><span class="line">            <span class="keyword">if</span> <span class="keyword">not</span> online_flag:</span><br><span class="line">                print(<span class="string">"还未上机，请上机！"</span>)</span><br><span class="line">                <span class="keyword">continue</span></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                end_time = get_time()</span><br><span class="line">                end_num = int(end_time[<span class="number">0</span>:<span class="number">2</span>])</span><br><span class="line">                sum = end_num - start_num</span><br><span class="line">                sum = sum <span class="keyword">if</span>(sum&gt;=<span class="number">0</span>) <span class="keyword">else</span> sum+<span class="number">24</span></span><br><span class="line">                sum = sum+<span class="number">1</span> <span class="keyword">if</span>(sum==<span class="number">0</span>) <span class="keyword">else</span> sum</span><br><span class="line">                print(<span class="string">"已下机！下机时间为："</span>+end_time+<span class="string">"\n上机时长(h)："</span>+str(sum)+<span class="string">"\t剩余机时(h)："</span>+str(people.get_stu_time()-sum))</span><br><span class="line">                text.append(<span class="string">"下机时间："</span>+end_time+<span class="string">"\n上机时长(h)："</span>+str(sum)+<span class="string">"\t"</span>+people.get_stu_name()+<span class="string">"剩余机时(h)："</span>+str(people.get_stu_time()-sum))</span><br><span class="line">                people.set_stu_time(str(people.get_stu_time()-sum))</span><br><span class="line">                down_flag = <span class="keyword">True</span></span><br><span class="line">                <span class="keyword">continue</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">elif</span> select == <span class="number">4</span>:</span><br><span class="line">            <span class="keyword">if</span> <span class="keyword">not</span> input_flag:</span><br><span class="line">                print(<span class="string">"未录入学生信息，请录入！"</span>)</span><br><span class="line">                <span class="keyword">continue</span></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                people.print()</span><br><span class="line">                add_time = eval(input(<span class="string">"请输入机时："</span>))</span><br><span class="line">                people.set_stu_time(str(add_time+people.get_stu_time()))</span><br><span class="line">                people.print()</span><br><span class="line"></span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="keyword">if</span> down_flag:</span><br><span class="line">                print(<span class="string">"3s后退出系统，感谢使用！"</span>)</span><br><span class="line">                time.sleep(<span class="number">3</span>) <span class="comment"># 延迟3s，显示提示文字</span></span><br><span class="line">                <span class="keyword">break</span> <span class="comment"># 退出系统 写入文件</span></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                print(<span class="string">"请下机！"</span>)</span><br><span class="line">                <span class="keyword">continue</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">#写入computer.txt文件</span></span><br><span class="line">    fo = open(<span class="string">"D:\\computer.txt"</span>,<span class="string">"w"</span>,encoding=<span class="string">"utf-8"</span>)</span><br><span class="line">    fo.write(<span class="string">"\n"</span>.join(text)) </span><br><span class="line">    fo.close()</span><br><span class="line">    </span><br><span class="line"><span class="keyword">if</span> __name__==<span class="string">"__main__"</span>:</span><br><span class="line">    main()</span><br></pre></td></tr></table></figure><h2 id="量化交易代码分析与调试"><a href="#量化交易代码分析与调试" class="headerlink" title="量化交易代码分析与调试"></a>量化交易代码分析与调试</h2><p>由于python的版本问题和一些库的导入问题所以还未调试成功，先挂上代码。以后改篇再论。<br></p><figure class="highlight py"><figcaption><span>主要代码</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#! /usr/bin/env python </span></span><br><span class="line"><span class="comment">#-*- encoding: utf-8 -*- </span></span><br><span class="line"><span class="comment">#author pythontab.com </span></span><br><span class="line"><span class="keyword">import</span> wx</span><br><span class="line"><span class="keyword">import</span> wx.adv</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> pandas <span class="keyword">as</span> pd</span><br><span class="line"><span class="keyword">import</span> pandas_datareader.data <span class="keyword">as</span> web</span><br><span class="line"><span class="keyword">import</span> matplotlib</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">from</span> matplotlib.figure <span class="keyword">import</span> Figure  </span><br><span class="line"><span class="keyword">import</span> matplotlib.dates <span class="keyword">as</span> mdates</span><br><span class="line"><span class="keyword">import</span> mpl_finance <span class="keyword">as</span> mpf</span><br><span class="line"><span class="keyword">from</span> matplotlib.backends.backend_wxagg <span class="keyword">import</span> FigureCanvasWxAgg <span class="keyword">as</span> FigureCanvas</span><br><span class="line"><span class="keyword">import</span> matplotlib.gridspec <span class="keyword">as</span> gridspec<span class="comment">#分割子图</span></span><br><span class="line"><span class="keyword">import</span> datetime</span><br><span class="line"><span class="keyword">import</span> talib</span><br><span class="line"><span class="keyword">import</span> csv,os</span><br><span class="line"><span class="keyword">import</span> codecs</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> RedefPanelMod <span class="keyword">import</span> MPL_Panel_Base,Loop_Panel_Base</span><br><span class="line"><span class="keyword">from</span> StockDataMod <span class="keyword">import</span> GetStockDatPro</span><br><span class="line"><span class="keyword">from</span> IndicatStrateMod <span class="keyword">import</span> Excave_Indic_Base, QuantPickTimeSys,FactorPickStockAng</span><br><span class="line"></span><br><span class="line">plt.rcParams[<span class="string">'font.sans-serif'</span>]=[<span class="string">'SimHei'</span>] <span class="comment">#用来正常显示中文标签</span></span><br><span class="line">plt.rcParams[<span class="string">'axes.unicode_minus'</span>]=<span class="keyword">False</span> <span class="comment">#用来正常显示负号</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">UserDialog</span><span class="params">(wx.Dialog)</span>:</span><span class="comment"># user-defined</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self,parent,text)</span>:</span></span><br><span class="line">        wx.Dialog.__init__(self,parent,<span class="number">-1</span>,<span class="string">u"选股提示"</span>,size=(<span class="number">400</span>,<span class="number">500</span>),style=wx.CAPTION|wx.CLOSE_BOX|wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX)</span><br><span class="line">        </span><br><span class="line">        sizer = wx.BoxSizer(wx.VERTICAL)</span><br><span class="line">        </span><br><span class="line">        pstock_Text = wx.StaticText(self, <span class="number">-1</span>, <span class="string">u'选股策略筛选结果'</span>) </span><br><span class="line">        pstock_Text.SetFont(wx.Font(<span class="number">18</span>,wx.DEFAULT,wx.NORMAL,wx.BOLD))</span><br><span class="line">        pstock_sure = wx.TextCtrl(self, <span class="number">-1</span>, <span class="string">"角度值:\n"</span>,size=(<span class="number">350</span>,<span class="number">300</span>),style = wx.TE_MULTILINE|wx.TE_READONLY)<span class="comment">#多行|只读</span></span><br><span class="line">        pstock_sure.SetFont(wx.Font(<span class="number">10</span>,wx.DEFAULT,wx.NORMAL,wx.BOLD))</span><br><span class="line"></span><br><span class="line">        okbtn = wx.Button(self,wx.ID_OK,<span class="string">u"确认"</span>)</span><br><span class="line">        okbtn.SetDefault()</span><br><span class="line">       </span><br><span class="line">        sizer.Add(pstock_Text,flag=wx.ALIGN_CENTER)</span><br><span class="line">        sizer.Add(pstock_sure,flag=wx.ALIGN_CENTER)</span><br><span class="line">        sizer.Add(okbtn,flag=wx.ALIGN_CENTER)       </span><br><span class="line">        self.SetSizer(sizer)</span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> text:pstock_sure.AppendText(i)</span><br><span class="line">    </span><br><span class="line">        </span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Frame</span><span class="params">(wx.Frame)</span>:</span>   </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span>   </span><br><span class="line">        wx.Frame.__init__(self, parent = <span class="keyword">None</span>, title = <span class="string">u'量化软件'</span>, size=(<span class="number">1500</span>,<span class="number">800</span>),   </span><br><span class="line">                      style=wx.DEFAULT_FRAME_STYLE^wx.MAXIMIZE_BOX)   </span><br><span class="line">        <span class="comment">#创建显示区面板</span></span><br><span class="line">        self.DispPanel = MPL_Panel_Base(self)</span><br><span class="line">        self.BackPanel = Loop_Panel_Base(self)</span><br><span class="line">        self.am = self.DispPanel.am</span><br><span class="line">        self.vol = self.DispPanel.vol</span><br><span class="line">        self.devol = self.DispPanel.devol</span><br><span class="line">        self.macd = self.DispPanel.macd        </span><br><span class="line">        </span><br><span class="line">        <span class="comment">#创建参数区面板</span></span><br><span class="line">        self.ParaPanel = wx.Panel(self,<span class="number">-1</span>)</span><br><span class="line">        </span><br><span class="line">        paraInput_Box = wx.StaticBox(self.ParaPanel, <span class="number">-1</span>, <span class="string">u'参数输入'</span>) </span><br><span class="line">        paraInput_Sizer = wx.StaticBoxSizer(paraInput_Box, wx.VERTICAL)    </span><br><span class="line">        self.StNameCodedict = &#123;<span class="string">u"开山股份"</span>:<span class="string">"300257.SZ"</span>,<span class="string">u"浙大网新"</span>:<span class="string">"600797.SS"</span>,<span class="string">u"水晶光电"</span>:<span class="string">"002273.SZ"</span>, <span class="string">u"高鸿股份"</span>:<span class="string">"000851.SZ"</span>&#125;</span><br><span class="line">        </span><br><span class="line">        <span class="comment">#初始化股票代码变量</span></span><br><span class="line">        self.stockName_Val = <span class="string">u"开山股份"</span></span><br><span class="line">        self.stockCode_Val = self.StNameCodedict[self.stockName_Val]</span><br><span class="line">        </span><br><span class="line">        self.stockName_CMBO = wx.ComboBox(self.ParaPanel, <span class="number">-1</span>,self.stockName_Val, choices = list(self.StNameCodedict.keys()), style = wx.CB_READONLY|wx.CB_DROPDOWN) <span class="comment">#股票名称</span></span><br><span class="line">        stockCode_Text = wx.StaticText(self.ParaPanel, <span class="number">-1</span>, <span class="string">u'股票名称'</span>) </span><br><span class="line"></span><br><span class="line">       <span class="comment">#策略选取</span></span><br><span class="line">        strate_Text = wx.StaticText(self.ParaPanel, <span class="number">-1</span>, <span class="string">u'策略名称'</span>) </span><br><span class="line">        strate_Combo_Val = [<span class="string">u"双趋势融合"</span>, <span class="string">u"阿尔法"</span>, <span class="string">u"布林带"</span>]</span><br><span class="line">        self.pickstrate_Val = <span class="string">u"双趋势融合"</span></span><br><span class="line">        self.pickstrate_CMBO = wx.ComboBox(self.ParaPanel, <span class="number">-1</span>, self.pickstrate_Val, choices = strate_Combo_Val, style = wx.CB_READONLY|wx.CB_DROPDOWN) <span class="comment">#策略名称        </span></span><br><span class="line"></span><br><span class="line">        <span class="comment">#日历控件选择数据周期</span></span><br><span class="line">        self.dpcEndTime = wx.adv.DatePickerCtrl(self.ParaPanel, <span class="number">-1</span>,style = wx.adv.DP_DROPDOWN|wx.adv.DP_SHOWCENTURY|wx.adv.DP_ALLOWNONE)<span class="comment">#结束时间</span></span><br><span class="line">        self.dpcStartTime = wx.adv.DatePickerCtrl(self.ParaPanel, <span class="number">-1</span>,style = wx.adv.DP_DROPDOWN|wx.adv.DP_SHOWCENTURY|wx.adv.DP_ALLOWNONE)<span class="comment">#起始时间</span></span><br><span class="line">        DateTimeNow = wx.DateTime.Now()<span class="comment">#wx.DateTime格式"03/03/18 00:00:00"</span></span><br><span class="line">       <span class="comment">#DateTimeNow = datetime.datetime.fromtimestamp(wx.DateTime.Now().GetTicks())</span></span><br><span class="line">       <span class="comment">#DateTimeNow = datetime.datetime.fromtimestamp(DateTimeNow)</span></span><br><span class="line">        self.dpcEndTime.SetValue(DateTimeNow)</span><br><span class="line">        DateTimeNow.SetYear(DateTimeNow.year<span class="number">-1</span>)</span><br><span class="line">        self.dpcStartTime.SetValue(DateTimeNow)</span><br><span class="line">        stockData_Text = wx.StaticText(self.ParaPanel, <span class="number">-1</span>, <span class="string">u'日期(Start-End)'</span>)</span><br><span class="line">        </span><br><span class="line">        <span class="comment">#初始化时间变量</span></span><br><span class="line">        dateVal = self.dpcStartTime.GetValue() </span><br><span class="line">        self.stockSdate_Val = datetime.datetime(dateVal.year,dateVal.month+<span class="number">1</span>,dateVal.day)</span><br><span class="line">        dateVal = self.dpcEndTime.GetValue() </span><br><span class="line">        self.stockEdate_Val = datetime.datetime(dateVal.year,dateVal.month+<span class="number">1</span>,dateVal.day)</span><br><span class="line"></span><br><span class="line">        paraInput_Sizer.Add(stockCode_Text,proportion=<span class="number">0</span>,flag=wx.EXPAND|wx.ALL,border=<span class="number">2</span>)</span><br><span class="line">        paraInput_Sizer.Add(self.stockName_CMBO, <span class="number">0</span>, wx.EXPAND|wx.ALL|wx.CENTER, <span class="number">2</span>)</span><br><span class="line">        paraInput_Sizer.Add(stockData_Text,proportion=<span class="number">0</span>,flag=wx.EXPAND|wx.ALL,border=<span class="number">2</span>)</span><br><span class="line">        paraInput_Sizer.Add(self.dpcStartTime, <span class="number">0</span>, wx.EXPAND|wx.ALL|wx.CENTER, <span class="number">2</span>) </span><br><span class="line">        paraInput_Sizer.Add(self.dpcEndTime, <span class="number">0</span>, wx.EXPAND|wx.ALL|wx.CENTER, <span class="number">2</span>) </span><br><span class="line">        paraInput_Sizer.Add(strate_Text, <span class="number">0</span>, wx.EXPAND|wx.ALL|wx.CENTER, <span class="number">2</span>)</span><br><span class="line">        paraInput_Sizer.Add(self.pickstrate_CMBO, <span class="number">0</span>, wx.EXPAND|wx.ALL|wx.CENTER, <span class="number">2</span>)</span><br><span class="line">        </span><br><span class="line">        RadioList = [<span class="string">"不显示"</span>,<span class="string">"跳空缺口"</span>, <span class="string">"金叉/死叉"</span>, <span class="string">"N日突破"</span>] </span><br><span class="line">        self.StratInputBox = wx.RadioBox(self.ParaPanel, <span class="number">-1</span>, label=<span class="string">u'指标提示'</span>, choices=RadioList,majorDimension = <span class="number">4</span>, style = wx.RA_SPECIFY_ROWS) </span><br><span class="line">        self.StratInputBox.Bind(wx.EVT_RADIOBOX,self.OnRadioBox_Indicator) </span><br><span class="line">        <span class="comment">#初始化指标变量</span></span><br><span class="line">        self.IndicatInput_Val = self.StratInputBox.GetStringSelection()  </span><br><span class="line">        </span><br><span class="line">        self.TextAInput = wx.TextCtrl(self.ParaPanel, <span class="number">-1</span>, <span class="string">"交易信息提示:"</span>, style = wx.TE_MULTILINE|wx.TE_READONLY)<span class="comment">#多行|只读</span></span><br><span class="line"></span><br><span class="line">        vboxnetA = wx.BoxSizer(wx.VERTICAL)<span class="comment">#纵向box </span></span><br><span class="line">        vboxnetA.Add(paraInput_Sizer,proportion=<span class="number">0</span>,flag=wx.EXPAND|wx.BOTTOM,border=<span class="number">2</span>) <span class="comment">#proportion参数控制容器尺寸比例</span></span><br><span class="line">        vboxnetA.Add(self.StratInputBox,proportion=<span class="number">0</span>,flag=wx.EXPAND|wx.BOTTOM,border=<span class="number">2</span>)         </span><br><span class="line">        vboxnetA.Add(self.TextAInput,proportion=<span class="number">1</span>,flag=wx.EXPAND|wx.ALL,border=<span class="number">2</span>) </span><br><span class="line">        self.ParaPanel.SetSizer(vboxnetA)</span><br><span class="line">        </span><br><span class="line">        <span class="comment">#创建Right面板</span></span><br><span class="line">        self.CtrlPanel = wx.Panel(self,<span class="number">-1</span>) </span><br><span class="line">        <span class="comment">#创建FlexGridSizer布局网格</span></span><br><span class="line">        self.FlexGridSizer=wx.FlexGridSizer(rows=<span class="number">3</span>, cols=<span class="number">1</span>, vgap=<span class="number">3</span>, hgap=<span class="number">3</span>)  </span><br><span class="line">        </span><br><span class="line">        <span class="comment">#行情按钮</span></span><br><span class="line">        self.Firmoffer = wx.Button(self.CtrlPanel,<span class="number">-1</span>,<span class="string">"行情"</span>)</span><br><span class="line">        self.Firmoffer.Bind(wx.EVT_BUTTON,self.FirmEvent)<span class="comment">#绑定行情按钮事件  </span></span><br><span class="line">        <span class="comment">#选股按钮</span></span><br><span class="line">        self.Stockpick = wx.Button(self.CtrlPanel,<span class="number">-1</span>,<span class="string">"选股"</span>)  </span><br><span class="line">        self.Stockpick.Bind(wx.EVT_BUTTON,self.PstockpEvent)<span class="comment">#绑定选股按钮事件</span></span><br><span class="line">        <span class="comment">#回测按钮  </span></span><br><span class="line">        self.Backtrace = wx.Button(self.CtrlPanel,<span class="number">-1</span>,<span class="string">"回测"</span>)  </span><br><span class="line">        self.Backtrace.Bind(wx.EVT_BUTTON,self.BackEvent)<span class="comment">#绑定回测按钮事件</span></span><br><span class="line">         </span><br><span class="line">        <span class="comment">#加入Sizer中  </span></span><br><span class="line">        self.FlexGridSizer.Add(self.Firmoffer,proportion = <span class="number">1</span>, border = <span class="number">5</span>,flag = wx.ALL | wx.EXPAND)  </span><br><span class="line">        self.FlexGridSizer.Add(self.Stockpick,proportion = <span class="number">1</span>, border = <span class="number">5</span>,flag = wx.ALL | wx.EXPAND)  </span><br><span class="line">        self.FlexGridSizer.Add(self.Backtrace,proportion = <span class="number">1</span>, border = <span class="number">5</span>,flag = wx.ALL | wx.EXPAND) </span><br><span class="line">        self.FlexGridSizer.SetFlexibleDirection(wx.BOTH)  </span><br><span class="line">        </span><br><span class="line">        self.CtrlPanel.SetSizer(self.FlexGridSizer)  </span><br><span class="line">        </span><br><span class="line">        self.HBoxPanel = wx.BoxSizer(wx.HORIZONTAL)</span><br><span class="line">        self.HBoxPanel.Add(self.ParaPanel,proportion = <span class="number">1.5</span>, border = <span class="number">2</span>,flag = wx.EXPAND|wx.ALL) </span><br><span class="line">        self.HBoxPanel.Add(self.DispPanel,proportion = <span class="number">8</span>, border = <span class="number">2</span>,flag = wx.EXPAND|wx.ALL )         </span><br><span class="line">        self.HBoxPanel.Add(self.CtrlPanel,proportion = <span class="number">1</span>, border = <span class="number">2</span>,flag = wx.EXPAND|wx.ALL ) </span><br><span class="line">        self.SetSizer(self.HBoxPanel)    </span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">ProcessStock</span><span class="params">(self)</span>:</span>         </span><br><span class="line">        <span class="comment">#df_stockload = web.DataReader("600797.SS", "yahoo", datetime.datetime(2017,1,1), datetime.date.today())</span></span><br><span class="line">        df_stockload = GetStockDatPro(self.stockCode_Val,self.stockSdate_Val, self.stockEdate_Val)</span><br><span class="line"></span><br><span class="line">        <span class="string">""" 绘制移动平均线图 """</span></span><br><span class="line">        <span class="comment">#self.am.plot(self.numic[0:self.butNum],self.close[0:self.butNum],'#0f0ff0',linewidth=1.0)</span></span><br><span class="line">        </span><br><span class="line">        dispCont_List = []</span><br><span class="line"></span><br><span class="line">        examp_trade= Excave_Indic_Base()</span><br><span class="line">        <span class="keyword">if</span> self.IndicatInput_Val == <span class="string">u"金叉/死叉"</span>:  </span><br><span class="line">            dispCont_pd,dispCont_List = examp_trade.plot_Aver_Cross(df_stockload)</span><br><span class="line">            self.DispPanel.draw_avercross(df_stockload,dispCont_pd)</span><br><span class="line">        <span class="keyword">elif</span> self.IndicatInput_Val == <span class="string">u"跳空缺口"</span>:</span><br><span class="line">            dispCont_pd,dispCont_List = examp_trade.plot_Jump_Thrd(df_stockload)</span><br><span class="line">            self.DispPanel.draw_jumpgap(df_stockload,dispCont_pd)</span><br><span class="line">        <span class="keyword">elif</span> self.IndicatInput_Val == <span class="string">u"N日突破"</span>:</span><br><span class="line">            dispCont_pd,dispCont_List = examp_trade.plot_Ndays_Break(df_stockload)</span><br><span class="line">            self.DispPanel.draw_ndaysbreak(df_stockload,dispCont_pd)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            dispCont_List = dispCont_List</span><br><span class="line">            </span><br><span class="line">        self.TextAInput.SetValue(<span class="string">u"指标提示信息如下:"</span>+<span class="string">'\n'</span>)</span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> dispCont_List:self.TextAInput.AppendText(i)</span><br><span class="line"></span><br><span class="line">        numic = np.arange(<span class="number">0</span>,len(df_stockload.index))</span><br><span class="line">        butNum = len(df_stockload.index)</span><br><span class="line">        self.DispPanel.xylabel_tick_lim(self.stockName_Val,df_stockload.index)</span><br><span class="line">        self.DispPanel.draw_subgraph(df_stockload,numic)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">ProcessLoop</span><span class="params">(self)</span>:</span> </span><br><span class="line"></span><br><span class="line">        df_stockload = GetStockDatPro(self.stockCode_Val,self.stockSdate_Val, self.stockEdate_Val)</span><br><span class="line">        dispCont_List = []</span><br><span class="line">        <span class="keyword">if</span> self.pickstrate_Val == <span class="string">u"双趋势融合"</span>:  </span><br><span class="line">            <span class="comment">#多趋势融合策略执行 """</span></span><br><span class="line">            examp_trade= QuantPickTimeSys(df_stockload)</span><br><span class="line">            dispCont_List = examp_trade.run_factor_plot(self.BackPanel.trade,self.BackPanel.total,self.BackPanel.profit)           </span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="comment">#执行其他策略</span></span><br><span class="line">            <span class="keyword">pass</span>    </span><br><span class="line">            </span><br><span class="line">        self.TextAInput.SetValue(<span class="string">u"策略提示信息如下:"</span>+<span class="string">'\n'</span>)</span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> dispCont_List:self.TextAInput.AppendText(i)</span><br><span class="line">        self.BackPanel.xylabel_tick_lim(self.stockName_Val)</span><br><span class="line">        </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">reFlashLoop</span><span class="params">(self)</span>:</span> </span><br><span class="line">        self.BackPanel.clear_subgraph()<span class="comment">#必须清理图形才能显示下一幅图</span></span><br><span class="line">        self.ProcessLoop()</span><br><span class="line">        self.BackPanel.update_subgraph()<span class="comment">#必须刷新才能显示下一幅图 </span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">reFlashFrame</span><span class="params">(self)</span>:</span> </span><br><span class="line">        self.DispPanel.clear_subgraph()<span class="comment">#必须清理图形才能显示下一幅图</span></span><br><span class="line">        self.ProcessStock()</span><br><span class="line">        self.DispPanel.update_subgraph()<span class="comment">#必须刷新才能显示下一幅图 </span></span><br><span class="line">        </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">FirmEvent</span><span class="params">(self,event)</span>:</span></span><br><span class="line">        <span class="comment">#显示行情面板</span></span><br><span class="line">        self.HBoxPanel.Hide(self.BackPanel)</span><br><span class="line">        self.HBoxPanel.Replace(self.BackPanel,self.DispPanel)</span><br><span class="line">        self.HBoxPanel.Show(self.DispPanel)</span><br><span class="line">        <span class="comment">#self.HBoxPanel.Remove(self.BackPanel)</span></span><br><span class="line">        self.SetSizer(self.HBoxPanel)  </span><br><span class="line">        self.HBoxPanel.Layout()    </span><br><span class="line">    </span><br><span class="line">        <span class="comment">#获取列表股票代码和起始时间</span></span><br><span class="line">        self.stockName_Val = self.stockName_CMBO.GetString(self.stockName_CMBO.GetSelection())</span><br><span class="line">        self.stockCode_Val = self.StNameCodedict[self.stockName_Val]</span><br><span class="line"></span><br><span class="line">        dateVal = self.dpcStartTime.GetValue() </span><br><span class="line">        self.stockSdate_Val = datetime.datetime(dateVal.year,dateVal.month+<span class="number">1</span>,dateVal.day)</span><br><span class="line">        dateVal = self.dpcEndTime.GetValue() </span><br><span class="line">        self.stockEdate_Val = datetime.datetime(dateVal.year,dateVal.month+<span class="number">1</span>,dateVal.day)</span><br><span class="line"></span><br><span class="line">        self.reFlashFrame()</span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">BackEvent</span><span class="params">(self,event)</span>:</span>       </span><br><span class="line">        <span class="comment">#显示回测面板</span></span><br><span class="line">        self.HBoxPanel.Hide(self.DispPanel)</span><br><span class="line">        self.HBoxPanel.Replace(self.DispPanel,self.BackPanel) </span><br><span class="line">        self.HBoxPanel.Show(self.BackPanel)</span><br><span class="line">        <span class="comment">#self.HBoxPanel.Remove(self.DispPanel)</span></span><br><span class="line">        self.SetSizer(self.HBoxPanel)  </span><br><span class="line">        self.HBoxPanel.Layout()</span><br><span class="line"></span><br><span class="line">        <span class="comment">#获取策略名称</span></span><br><span class="line">        self.pickstrate_Val = self.pickstrate_CMBO.GetString(self.pickstrate_CMBO.GetSelection())</span><br><span class="line">        self.reFlashLoop()</span><br><span class="line">        </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">PstockpEvent</span><span class="params">(self,event)</span>:</span></span><br><span class="line">        dispCont_List = []</span><br><span class="line">        <span class="string">""" 选股策略执行 """</span></span><br><span class="line">        examp_trade= FactorPickStockAng()</span><br><span class="line">        <span class="keyword">for</span> index, stockName <span class="keyword">in</span> enumerate(self.StNameCodedict.keys()) : </span><br><span class="line">            print(<span class="string">"stockName"</span>,stockName,self.StNameCodedict[stockName])</span><br><span class="line">            df_stockload = GetStockDatPro(self.StNameCodedict[stockName],self.stockSdate_Val, self.stockEdate_Val)</span><br><span class="line">            df_stockload.fillna(method=<span class="string">'bfill'</span>,inplace=<span class="keyword">True</span>)<span class="comment">#后一个数据填充NAN1</span></span><br><span class="line">            dispCont_List.append(stockName+<span class="string">'\n'</span>+examp_trade.fit_pick(df_stockload.Close)+<span class="string">'\n'</span>)</span><br><span class="line">        print(dispCont_List)</span><br><span class="line">        <span class="string">""" 选股策略执行 """</span></span><br><span class="line">        <span class="string">""" 自定义提示框 """</span></span><br><span class="line">        myPickStock = UserDialog(self,dispCont_List)    </span><br><span class="line">        <span class="keyword">if</span> myPickStock.ShowModal() == wx.ID_OK:</span><br><span class="line">            <span class="keyword">pass</span> </span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">        <span class="string">""" 自定义提示框 """</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">OnRadioBox_Indicator</span><span class="params">(self,event)</span>:</span>  </span><br><span class="line">        self.IndicatInput_Val = self.StratInputBox.GetStringSelection()</span><br><span class="line"></span><br><span class="line">      </span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">App</span><span class="params">(wx.App)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">OnInit</span><span class="params">(self)</span>:</span></span><br><span class="line">        self.frame = Frame()  </span><br><span class="line">        self.frame.ProcessStock()</span><br><span class="line">        self.frame.Show()</span><br><span class="line">        self.SetTopWindow(self.frame)</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">True</span></span><br><span class="line">    </span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:   </span><br><span class="line">    app = App()</span><br><span class="line">    app.MainLoop()</span><br></pre></td></tr></table></figure><p></p></div><div class="popular-posts-header"><i class="fa fa-link"></i> 相关文章</div><!--[if !IE]><!--><details><summary style="cursor:pointer">点击查看</summary><!--<![endif]--><ul class="popular-posts"><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\jsoninfo.html" rel="bookmark">Python如何操作Json？</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\csdnvisiter.html" rel="bookmark">使用Python刷csdn访问量</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\pysx1.html" rel="bookmark">python实训总结Ⅰ</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\mx2wx.html" rel="bookmark">python实战：模拟post请求定时获取后台数据并打包发送至微信</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\pysettime.html" rel="bookmark">python设置程序每天8点定时执行任务</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\pyinstallererror.html" rel="bookmark">安装pyinstaller出错的解决办法及csdn工具实例打包</a></div></li></ul><!--[if IE]><!--></details><!--<![endif]--><div><div style="padding:10px 0;margin:20px auto;width:90%;text-align:center"><div>欢迎关注公众号，感谢支持 ！</div><button id="rewardButton" disable="enable" onclick="var qr = document.getElementById(&quot;QR&quot;); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}"><span>赞赏</span></button><div id="QR" style="display:none"><div id="wechat" style="display:inline-block"><img id="wechat_qr" src="/images/wechatpay.gif" alt="李瑞豪 微信支付"><p>微信支付</p></div><div id="alipay" style="display:inline-block"><img id="alipay_qr" src="/images/alipay.gif" alt="李瑞豪 支付宝"><p>支付宝</p></div></div></div></div><div class="copyright-box"><ul class="post-copyright"><li class="post-copyright-author"><strong>本文作者： </strong>李瑞豪</li><li><strong>修改时间： </strong>2019-10-19 10:46:42</li><li class="post-copyright-link"><strong>本文链接：</strong> <a href="https://lruihao.cn/posts/pysx2.html" title="python实训总结Ⅱ">https://lruihao.cn/posts/pysx2.html</a></li><li class="post-copyright-license"><strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noopener noreferrer" target="_blank"><i class="fa fa-fw fa-creative-commons"></i> BY-NC-SA 4.0</a> 许可协议。转载请注明出处！</li></ul></div><div class="post-tags"><a href="/tags/Python/" rel="tag"><i class="fa fa-tag"></i> Python</a></div><footer class="post-footer"><div class="post-nav"><div class="post-nav-next post-nav-item"><a href="/posts/pysx1.html" rel="next" title="python实训总结Ⅰ"><i class="fa fa-chevron-left"></i> python实训总结Ⅰ</a></div><span class="post-nav-divider"></span><div class="post-nav-prev post-nav-item"><a href="/posts/wamproot.html" rel="prev" title="WAMPServer自定义网站根目录等设置">WAMPServer自定义网站根目录等设置 <i class="fa fa-chevron-right"></i></a></div></div></footer></div></article></div></div><div class="comments" id="comments"></div></div><div class="sidebar-toggle"><div class="sidebar-toggle-line-wrap"><span class="sidebar-toggle-line sidebar-toggle-line-first"></span> <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span> <span class="sidebar-toggle-line sidebar-toggle-line-last"></span></div></div><aside id="sidebar" class="sidebar"><div id="sidebar-dimmer"></div><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">文章目录</li><li class="sidebar-nav-overview" data-target="site-overview-wrap">站点概览</li></ul><div class="site-overview-wrap sidebar-panel"><div class="site-overview"><div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person"><img class="site-author-image" itemprop="image" src="/images/avatar.png" alt="李瑞豪"><p class="site-author-name" itemprop="name">李瑞豪</p><p class="site-description motion-element" itemprop="description">从ACM到Web，分享程序、技巧、干货，记录心情、学习、成长！</p></div><nav class="site-state motion-element"><div class="site-state-item site-state-posts"><a href="/archives/"><span class="site-state-item-count">176</span> <span class="site-state-item-name">日志</span></a></div><div class="site-state-item site-state-categories"><a href="/docs/categories/index.html"><span class="site-state-item-count">25</span> <span class="site-state-item-name">分类</span></a></div><div class="site-state-item site-state-tags"><a href="/docs/tags/index.html"><span class="site-state-item-count">122</span> <span class="site-state-item-name">标签</span></a></div></nav><div class="feed-link motion-element"><a href="/atom.xml" rel="alternate"><i class="fa fa-rss"></i> RSS</a></div><div class="links-of-author motion-element"><span class="links-of-author-item"><a href="https://github.com/Lruihao" title="GitHub &rarr; https://github.com/Lruihao" rel="external nofollow noopener noreferrer" target="_blank"><i class="fa fa-fw fa-github"></i></a> </span><span class="links-of-author-item"><a href="https://blog.csdn.net/qq_39520417" title="CSDN &rarr; https://blog.csdn.net/qq_39520417" rel="external nofollow noopener noreferrer" target="_blank"><i class="fa fa-fw fa-contao"></i></a> </span><span class="links-of-author-item"><a href="https://weibo.com/liahao" title="微博 &rarr; https://weibo.com/liahao" rel="external nofollow noopener noreferrer" target="_blank"><i class="fa fa-fw fa-weibo"></i></a> </span><span class="links-of-author-item"><a href="/images/qq.jpg" title="QQ &rarr; /images/qq.jpg"><i class="fa fa-fw fa-qq"></i></a> </span><span class="links-of-author-item"><a href="mailto:1074627678@qq.com" title="E-Mail &rarr; mailto:1074627678@qq.com" rel="external nofollow noopener noreferrer" target="_blank"><i class="fa fa-fw fa-envelope"></i></a></span></div><div class="cc-license motion-element" itemprop="license"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="external nofollow noopener noreferrer" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a></div><div class="links-of-blogroll motion-element links-of-blogroll-inline"><div class="links-of-blogroll-title"><i class="fa fa-fw fa-globe"></i> 书签</div><ul class="links-of-blogroll-list"><li class="links-of-blogroll-item"><a href="/docs/donators/" title="/docs/donators/">赞助记录</a>&ensp;</li><li class="links-of-blogroll-item"><a href="/docs/friends/" title="/docs/friends/">友情链接</a>&ensp;</li><li class="links-of-blogroll-item"><a href="/posts/links.html" title="/posts/links.html">收藏夹</a>&ensp;</li><li class="links-of-blogroll-item"><a href="/posts/font-mmt.html" title="/posts/font-mmt.html">MMT</a>&ensp;</li><li class="links-of-blogroll-item"><a href="http://md.lruihao.cn" title="http://md.lruihao.cn" rel="external nofollow noopener noreferrer" target="_blank">WXMD</a>&ensp;</li><li class="links-of-blogroll-item"><a href="/posts/webbiji.html" title="/posts/webbiji.html">WEB</a>&ensp;</li></ul></div></div></div><div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active"><div class="post-toc"><div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#6-19"><span class="nav-number">1.</span> <span class="nav-text">6.19</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#切片操作"><span class="nav-number">1.1.</span> <span class="nav-text">切片操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#字符串"><span class="nav-number">1.2.</span> <span class="nav-text">字符串</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#python原始字符串"><span class="nav-number">1.2.1.</span> <span class="nav-text">python原始字符串</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#长字符串"><span class="nav-number">1.2.2.</span> <span class="nav-text">长字符串</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#用-换行字符表示字符未结束"><span class="nav-number">1.2.3.</span> <span class="nav-text">用\换行字符表示字符未结束</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#格式化输出format"><span class="nav-number">1.3.</span> <span class="nav-text">格式化输出format</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#多变量赋值与交换（斐波那契数列）"><span class="nav-number">1.4.</span> <span class="nav-text">多变量赋值与交换（斐波那契数列）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#笑傲江湖统计字符-dict-文件流"><span class="nav-number">1.5.</span> <span class="nav-text">笑傲江湖统计字符(dict,文件流)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#numpy模块"><span class="nav-number">1.6.</span> <span class="nav-text">numpy模块</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#pandas模块"><span class="nav-number">1.7.</span> <span class="nav-text">pandas模块</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#6-20"><span class="nav-number">2.</span> <span class="nav-text">6.20</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#matplotlib绘图"><span class="nav-number">2.1.</span> <span class="nav-text">matplotlib绘图</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#爬虫"><span class="nav-number">2.2.</span> <span class="nav-text">爬虫</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#6-21"><span class="nav-number">3.</span> <span class="nav-text">6.21</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#类"><span class="nav-number">3.1.</span> <span class="nav-text">类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#GUI设计-wxPython"><span class="nav-number">3.2.</span> <span class="nav-text">GUI设计 wxPython</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#talib库的安装"><span class="nav-number">3.3.</span> <span class="nav-text">talib库的安装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#选择排序递归版"><span class="nav-number">3.4.</span> <span class="nav-text">选择排序递归版</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#机房上机系统-自我实践"><span class="nav-number">3.5.</span> <span class="nav-text">机房上机系统(自我实践)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#量化交易代码分析与调试"><span class="nav-number">3.6.</span> <span class="nav-text">量化交易代码分析与调试</span></a></li></ol></li></ol></div></div></div></div></aside></div></main><footer id="footer" class="footer"><div class="footer-inner"><div class="copyright">Copyright &copy; 2018 – <span itemprop="copyrightYear">2020</span> <span class="with-love" id="animate"><i class="fa fa-heartbeat"></i> </span><span class="author" itemprop="copyrightHolder">LRH.&ensp;</span> <span title="博客总字数"><i class="fa fa-edit"></i>&ensp;<span class="post-count">115.7k</span>字</span></div><div class="busuanzi-count"><script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span class="post-meta-item-icon"><i class="fa fa-user"></i> </span><span class="site-uv" title="总访客量"><span class="busuanzi-value" id="busuanzi_value_site_uv"><i class="fa fa-spinner fa-spin"></i></span>&thinsp;人次 </span><span class="post-meta-divider">|</span> <span class="run-times" title="网站运行时间">载入天数时分秒...</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="site-pv" title="总访问量"><span class="busuanzi-value" id="busuanzi_value_site_pv"><i class="fa fa-spinner fa-spin"></i></span>&thinsp;次</span></div><div class="weixin-box"><div class="weixin-menu"><div class="weixin-hover"><div class="weixin-description">微信扫一扫，订阅本博客</div></div></div></div><div class="beian" style="display:inline-block;height:20px;line-height:20px"><a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=43030402000254" rel="external nofollow noopener noreferrer"><img src="/images/gov.png" style="float:left" alt="公安">湘公网安备43030402000254号</a> <span class="post-meta-divider" style="color:#555">|</span> <span><a href="http://www.beian.miit.gov.cn" target="_blank" rel="external nofollow noopener noreferrer">湘ICP备18020535号</a></span></div></div></footer><div class="back-to-top"><i class="fa fa-arrow-up"></i> <span id="scrollpercent"><span>0</span>%</span></div></div><script type="text/javascript">"[object Function]"!==Object.prototype.toString.call(window.Promise)&&(window.Promise=null)</script><script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script><script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script><script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script><script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script><script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script><script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js"></script><script type="text/javascript" src="/lib/reading_progress/reading_progress.js"></script><script type="text/javascript" src="/js/src/utils.js?v=6.7.0"></script><script type="text/javascript" src="/js/src/motion.js?v=6.7.0"></script><script type="text/javascript" src="/js/src/affix.js?v=6.7.0"></script><script type="text/javascript" src="/js/src/schemes/pisces.js?v=6.7.0"></script><script type="text/javascript" src="/js/src/scrollspy.js?v=6.7.0"></script><script type="text/javascript" src="/js/src/post-details.js?v=6.7.0"></script><script type="text/javascript" src="/js/src/bootstrap.js?v=6.7.0"></script><script>$(".highlight").each(function(t,e){var n=$("<div>").addClass("highlight-wrap");$(e).after(n),n.append($("<button>").addClass("copy-btn").append("复制").on("click",function(t){var e=$(this).parent().find(".code").find(".line").map(function(t,e){return $(e).text()}).toArray().join("\n"),n=document.createElement("textarea");document.body.appendChild(n),n.style.position="absolute",n.style.top="0px",n.style.left="0px",n.value=e,n.select(),n.focus();var o=document.execCommand("copy");document.body.removeChild(n),o?$(this).text("复制成功"):$(this).text("复制失败"),$(this).blur()})).on("mouseleave",function(t){var e=$(this).find(".copy-btn");setTimeout(function(){e.text("复制")},300)}).append(e)})</script><script>$("body").find("pre.mermaid").length&&$.ajax({type:"GET",url:"//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js",dataType:"script",cache:!0,success:function(){mermaid.initialize({theme:"forest",logLevel:3,flowchart:{curve:"linear"},gantt:{axisFormat:"%m/%d/%Y"},sequence:{actorMargin:50}})}})</script><script>function createTime(){var e=new Date,t=new Date("05/28/2018 20:01:01"),n=(e-t)/1e3,i=Math.floor(n/60/60/24),r=Math.floor(n/60/60-24*i),h=Math.floor(n/60-1440*i-60*r),a=Math.floor((e-t)/1e3-86400*i-3600*r-60*h);1===String(r).length&&(r="0"+r),1===String(h).length&&(h="0"+h),1===String(a).length&&(a="0"+a),document.querySelector(".run-times").innerHTML=i+"&thinsp;天&thinsp;"+r+"&thinsp;时&thinsp;"+h+"&thinsp;分&thinsp;"+a+"&thinsp;秒"}if(document.hidden)clearInterval(siteTime);else var siteTime=setInterval("createTime()",500)</script><script type="text/javascript" src="/js/src/console.js"></script><script async type="text/javascript" src="/js/src/night.js"></script><div class="cover"></div><script async type="text/javascript" src="/js/src/crash-cheat.js"></script><script src="/js/src/activate-power-mode.js"></script><script>POWERMODE.colorful=!0,POWERMODE.shake=!1,document.body.addEventListener("input",POWERMODE)</script><script type="text/javascript" src="/js/src/love.js"></script><script type="text/javascript" src="/js/src/link-card.js" defer></script><script type="text/javascript" src="/js/src/pageQRcode.js" defer></script><script src="//cdn1.lncld.net/static/js/3.11.1/av-min.js"></script><script src="//unpkg.com/valine/dist/Valine.min.js"></script><script>var GUEST=["nick","mail","link"],guest="nick,mail,link";guest=guest.split(",").filter(function(e){return-1<GUEST.indexOf(e)}),new Valine({el:"#comments",verify:!1,notify:!1,appId:"7HwTRT0Q0Tfrat6ugrT6P67c-gzGzoHsz",appKey:"mhTY1kuUmviCtQwkwOASfsfD",placeholder:"ヾﾉ≧∀≦)o~ 有事请留言！\n评论功能以邮件作为通知方式！\n如有必要请填写正确邮箱！",avatar:"wavatar",meta:guest,pageSize:"10",visitor:!0,lang:"zh-cn"})</script><script type="text/javascript">// Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });</script><script>!function(){var t=document.createElement("script"),e=window.location.protocol.split(":")[0];t.src="https"===e?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s)}()</script><script src="/lib/pangu/dist/pangu.min.js?v=3.3"></script><script type="text/javascript">pangu.spacingPage()</script><script src="/lib/bookmark/bookmark.min.js?v=1.0"></script><script type="text/javascript">bookmark.scrollToMark("manual","#更多")</script><script>!function(e){var r=Array.prototype.slice.call(document.querySelectorAll("img[data-original]"));function t(){for(var c=0;c<r.length;c++)t=r[c],void 0,0<=(n=t.getBoundingClientRect()).top&&0<=n.left&&n.top<=(e.innerHeight||document.documentElement.clientHeight)&&function(){var t,n,e,i,o=r[c];t=o,n=function(){r=r.filter(function(t){return o!==t})},e=new Image,i=t.getAttribute("data-original"),e.onload=function(){t.src=i,n&&n()},e.src=i}();var t,n}t(),e.addEventListener("scroll",function(){!function(t,n){clearTimeout(t.tId),t.tId=setTimeout(function(){t.call(n)},500)}(t,e)})}(this);</script></body></html>